package com.cdsxlc.common.enums;

import com.cdsxlc.common.utils.StringUtils;

/**
 * 数据类型枚举
 * @author JohnDeng
 * @datatime 2019年1月17日上午9:49:04
 */
public enum DataTypeEnums {
	
	CHAR("char","String", null),

	VARCHAR("varchar","String", null),

	BLOB("blob","byte[]", null),

	TEXT("text","String",null),

	INTEGER("integer","Long",null),

	TINYINT("tinyint","Integer",null),

	SMALLINT("varchar","Integer",null),

	MEDIUMINT("mediumint","Integer",null),

	BIT("bit","Boolean",null),

	BIGINT("bigint","Long", null),

	FLOAT("float","Float", null),

	DOUBLE("double","Double", null),

	DECIMAL("decimal","String", null),

	BOOLEAN("varchar","Integer", null),

	DATE("date","Date", "java.util.Date"),

	DATETIME("datetime","Date", "java.util.Date"),

	INT("int","Integer", null),

	TIMESTAMP("timestamp","Date", "java.util.Date");

	private final String mySqlDataType;

	private final String javaDataType;

	private final String referenceJar;

	public static DataTypeEnums getJavaDataTypeByMysqlDataType(String mySqlDataType) {
		for (DataTypeEnums e : DataTypeEnums.values()) {
			if (e.name().toLowerCase().equals(mySqlDataType)) {
				return e;
			}
		}
		return VARCHAR;
	}
	
	
	DataTypeEnums(String mySqlDataType, String javaDataType, String referenceJar) {
		this.mySqlDataType = mySqlDataType;
		this.javaDataType = javaDataType;
		this.referenceJar = referenceJar;
	}
	public String getMySqlDataType() {
		return mySqlDataType;
	}
	public String getJavaDataType() {
		return javaDataType;
	}
	public String getReferenceJar() {
		return StringUtils.isBlank(referenceJar) ? null : "import " + referenceJar + ";\n";
	}
}
